class_name MovingLogo extends Sprite2D

signal logo_node_ready

signal logo_move_up
signal logo_move_down
signal logo_move_left
signal logo_move_right

const SPEED = 5

var single_flag : bool = true
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	print('Logo=========_ready=========')
	# 因为所有子节点都继承自父类，因此也可以直接绑定父类方法处理
	#logo_node_ready.connect(get_parent()._node_ready.bind("this is a message from subnode"))
	
	# await的加入就可以解决这里发出的信号因为父结点的连接还没创建而丢失的问题
	await get_tree().process_frame
	print('send single:logo_node_ready---ready')
	logo_node_ready.emit()
	
	self.logo_move_up.connect(_move_up.bind("message"))
	self.logo_move_down.connect(_move_down)
	self.logo_move_left.connect(_move_left)
	self.logo_move_right.connect(_move_right)

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float):
	#self.position.x = self.position.x + 1
	#print(delta)
	#print(self.position)
	if self.single_flag:
		self.single_flag = false
		print('send single:logo_node_ready')
		logo_node_ready.emit()
		# 发送一个全局的信号
		EventBus.new_points.emit()
	return delta

func _move_up(msg:String, flag:int, bindmsg:String):
	print('%s (%s) - %d' % [msg, bindmsg, flag])
	self.position.y = self.position.y - SPEED
	
func _move_down():
	self.position.y = self.position.y + SPEED
	
func _move_left():
	self.position.x = self.position.x - SPEED
	
func _move_right():
	self.position.x = self.position.x + SPEED
